package com.chunfeng.mypen.controller;

import com.chunfeng.mypen.entity.Router;
import com.chunfeng.mypen.result.JsonRequest;
import com.chunfeng.mypen.service.RouterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 路由控制层
 *
 * @author by 春风能解释
 * <p>
 * 2023/11/15
 */
@RestController
@RequestMapping("/router")
@Api(value = "路由控制层", tags = "路由操作访问接口")
public class RouterController {

    /**
     * 路由业务层注入
     */
    @Autowired
    private RouterService routerService;

    /**
     * 条件查询路由
     *
     * @param current 当前页码
     * @param size    每页长度
     * @param router  条件
     * @return JSON
     */
    @GetMapping
    @ApiOperation(value = "分类筛选路由信息")
    public JsonRequest<List<Router>> lookRouter(
            @ApiParam(value = "当前页数", required = true)
            @RequestParam Integer current,
            @ApiParam(value = "每页长度", required = true)
            @RequestParam Integer size,
            @ApiParam(value = "条件", required = true)
            Router router) {
        return routerService.lookRouter(current, size, router);
    }

    /**
     * 添加一条路由信息
     *
     * @param router 待添加的路由
     * @return JSON
     */
    @PostMapping
    @ApiOperation(value = "新增一条路由信息")
    public JsonRequest<Integer> addOneRouter(
            @ApiParam(value = "待添加的路由信息", required = true)
            @RequestBody Router router) {
        return routerService.insertOneRouter(router);
    }

    /**
     * 修改一条路由信息
     *
     * @param router 待修改的路由信息
     * @return JSON
     */
    @PutMapping
    @ApiOperation(value = "修改一条路由信息")
    public JsonRequest<Integer> updateOneRouter(
            @ApiParam(value = "待修改的路由信息", required = true)
            @RequestBody Router router) {
        return routerService.updateOneRouter(router);
    }

    /**
     * 批量删除路由
     *
     * @param ids ID
     * @return JSON
     */
    @DeleteMapping
    @ApiOperation(value = "批量删除路由信息")
    public JsonRequest<Integer> deleteRouter(
            @ApiParam(value = "待删除的路由ID", required = true)
            @RequestBody List<String> ids) {
        return routerService.deleteRouter(ids);
    }
}
